<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>安装</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/res/layui/css/layui.css" media="all">
    <style>
        .required {
            color: #FF5722;
            font-weight: bold;
        }
    </style>
</head>
<body>
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-md12">
            {include file='index/header'}
            <div class="environment">
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                    <legend>数据库配置</legend>
                </fieldset>
                <blockquote class="layui-elem-quote">请正确配置数据库环境，否则运行程序会出现错误</blockquote>
                <form class="layui-form">
                    <table class="layui-table lay-even">
                        <colgroup>
                            <col width="150">
                            <col width="350">
                            <col>
                        </colgroup>
                        <thead>
                        </thead>
                        <tbody>
                        <tr>
                            <td><span class="required">*</span> 数据库地址</td>
                            <td><input type="text" name="db_host" lay-verify="required" lay-reqtext="请输入数据库地址" class="layui-input" placeholder="请输入数据库地址" value="localhost"></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><span class="required">*</span> 数据库用户</td>
                            <td><input type="text" name="db_user" lay-verify="required" lay-reqtext="请输入数据库用户" class="layui-input" placeholder="请输入数据库用户" value="root"></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><span class="required">*</span> 数据库密码</td>
                            <td><input type="password" name="db_pass" lay-verify="required" lay-reqtext="请输入数据库密码" class="layui-input" placeholder="请输入数据库密码"></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><span class="required">*</span> 数据库端口</td>
                            <td><input type="text" name="db_prt" lay-verify="required" lay-reqtext="请输入数据库端口" class="layui-input" placeholder="请输入数据库端口" value="3306"></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><span class="required">*</span> 数据库名称</td>
                            <td><input type="text" name="db_name" lay-verify="required" lay-reqtext="请输入数据库名称" class="layui-input" placeholder="请输入数据库名称" value="tp_cms"></td>
                            <td></td>
                        </tr>
                        </tbody>
                    </table>
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                        <legend>管理员账户</legend>
                    </fieldset>
                    <blockquote class="layui-elem-quote">用户登录后台</blockquote>
                    <table class="layui-table lay-even">
                        <colgroup>
                            <col width="150">
                            <col width="350">
                            <col>
                        </colgroup>
                        <thead>
                        </thead>
                        <tbody>
                        <tr>
                            <td><span class="required">*</span> 用户名</td>
                            <td><input type="text" name="username" lay-verify="required" lay-reqtext="请输入管理员名称" class="layui-input" placeholder="请输入管理员名称" value="超级管理员"></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><span class="required">*</span> 手机号</td>
                            <td><input type="text" name="phone" lay-verify="required|phone" lay-reqtext="请输入管理员手机|请输入正确的手机号" class="layui-input" placeholder="请输入管理员手机"></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><span class="required">*</span> 邮箱</td>
                            <td><input type="text" name="email" lay-verify="required|email" lay-reqtext="请输入管理员邮箱|请输入正确的邮箱格式" class="layui-input" placeholder="请输入管理员邮箱"></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><span class="required">*</span> 密码</td>
                            <td><input type="password" name="password" lay-verify="required" lay-reqtext="请输入密码" class="layui-input" placeholder="请输入密码"></td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><span class="required">*</span> 确认密码</td>
                            <td><input type="password" name="confirm_password" lay-verify="required" lay-reqtext="请输入确认密码" class="layui-input" placeholder="请输入确认密码">
                            </td>
                            <td></td>
                        </tr>
                        </tbody>
                    </table>
                    <div>
                        <button type="button" class="layui-btn layui-btn-primary back">上一步</button>
                        <button type="button" class="layui-btn" lay-submit lay-filter="layuiadmin-app-form-edit"
                                id="layuiadmin-app-form-edit">继续安装
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    {include file='index/footer'}
</div>
<script src="__STATIC__/res/layui/layui.js"></script>
<script>

    var DO_INSTALL_URL = '{:url("index/doInstall")}';
    var SUCCESS_URL  = '{:url("index/success")}';
    layui.config({
        base: '__STATIC__/res/' //静态资源所在路径
    }).use(['index', 'form'], function () {
        var $ = layui.$;
        var form = layui.form;
        $('.back').click(function () {
            history.back();
        })

        form.on('submit(layuiadmin-app-form-edit)', function (data) {
            var field = data.field; //获取提交的字段
            $.ajax({
                method: 'post',
                data: field,
                url: DO_INSTALL_URL,
                success: function (res) {
                    if (res.result.status) {
                        layer.msg(res.result.msg, {
                            offset: '15px'
                            , icon: 2
                            , time: 1000
                        });

                        return
                    }

                    location.href = SUCCESS_URL;
                }
            })
        });
    });
</script>
</body>
</html>